package com.ruoyi.web.controller.his;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.his.domain.HisTitle;
import com.ruoyi.his.service.HisTitleService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/hisTitle")
public class HisTitleController {
    @Autowired
    private HisTitleService hisTitleService;
    @Autowired
    private ISysUserService userService;

    @GetMapping("/getUserInfo")
    public List<SysUser> getUserInfo(){
        List<SysUser> userList = userService.getUserInfo();
        return userList;
    }
    @GetMapping("/registerTitle")
    public AjaxResult getRegisterTitle(@RequestParam(required = false) String signature)
    {
        HisTitle title = new HisTitle();
        title.setTagee("2");
        title.setSignature(signature);
        HisTitle hisTitle = hisTitleService.getTitleInfo(title);
        AjaxResult ajax = AjaxResult.success(hisTitle);
        return ajax;
    }
    @GetMapping("/loginTitle")
    public AjaxResult getLoginTitle(@RequestParam(required = false) String signature)
    {
        HisTitle title = new HisTitle();
        title.setTagee("1");
        title.setSignature(signature);
        HisTitle hisTitle = hisTitleService.getTitleInfo(title);
        AjaxResult ajax = AjaxResult.success(hisTitle);
        return ajax;
    }
    @PutMapping("changeRegisterTitle")
    public AjaxResult changeRegisterTitle(@RequestBody HisTitle hisTitle){
        hisTitle.setUpdateTime(new Date());
        int i = hisTitleService.changeRegisterTitle(hisTitle);
        if( i >0){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
    @PutMapping("changeLoginTitle")
    public AjaxResult changeLoginTitle(@RequestBody HisTitle hisTitle){
        hisTitle.setUpdateTime(new Date());
        int i = hisTitleService.changeLoginTitle(hisTitle);
        if( i >0){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
}

